<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理管理员</title>
    <script type="text/javascript" src="../common/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../common/commonQuery.js"></script>
    <script type="text/javascript" src="../common/commonManager.js"></script>
    <link rel="stylesheet" href="../common/common.css" type="text/css">
    <script type="text/javascript">

        function createTableHead() {
            var tr = "<tr>";
            tr += "<th align='left'>管理员id</th>"
            tr += "<th align='left'>类型</th>"
            tr += "<th align='left'>名称</th>"
            tr += "<th align='left'>操作</th>"
            tr += "</tr>"

            return tr;
        }

        function creteTableRow(info) {
            var tr = "<tr>";
            tr += "<td>" + info.managerId + "</td>";
            tr += "<td>" + toManagerTypeStr(info.type) + "</td>";
            tr += "<td>" + info.name + "</td>";
            tr += "<td><button onclick='deleteEntity(\"" + info.managerId + "\")'>删除</button></td>"
            tr += "</tr>"

            return tr;
        }

        function toManagerTypeStr(type) {
            if (type == 'ADMIN') {
                return "超级管理员";
            } else {
                return "普通管理员";
            }
        }

        function deleteEntity(managerId) {
            $.ajax({
                url: "../manager/manage/delete",
                data: {
                    managerId: managerId
                },
                success: function (ajaxResult) {
                    if (ajaxResult.success) {
                        query();
                    } else {
                        alert("删除失败，原因：" + ajaxResult.message);
                    }
                }
            });
        }

        function requestServer2(formName) {
            var form = $("#" + formName);
            $.ajax({
                url: form.attr("action"),
                data: form.serialize(),
                success: function (ajaxResult) {
                    if (ajaxResult.success) {
                        query();
                        alert("成功")
                    } else {
                        alert("失败，原因：" + ajaxResult.message);
                    }
                },
                error: function () {
                    alert("请求服务失败");
                }
            });
        }

    </script>
</head>
<body>
<br>
<div>
    <form id="queryForm" action="../manager/manage/query">
        管理员id：<input type="text" name="managerId">
        类型：
        <select name="type">
            <option value="" selected="true"></option>
            <option value="NORMAL">普通管理员</option>
            <option value="ADMIN">超级管理员</option>
        </select>
        名称：<input type="text" name="name">
        <input type="button" onclick="pageNo = 1;query();" value="查询">
    </form>
</div>
<div id="tableDiv" class="table-solid"></div>
<div id="pageFoot">
    <button onclick="previousPage()">上一页</button>
    <span id="currentPageNo">1</span>
    <button onclick="nextPage()">下一页</button>
    总页数：<span id="totalPage"></span>
</div>
<br/><br/>
<table width="100%">
    <tr>
        <td valign="top" width="30%">
            <div>
                新增管理员：
                <form id="addForm" action="../manager/manage/add">
                    <table>
                        <tr>
                            <td align="right">管理员id：</td>
                            <td><input type="text" name="managerId"></td>
                        </tr>
                        <tr>
                            <td align="right">类型：</td>
                            <td>
                                <select name="type">
                                    <option value="NORMAL" selected="true">普通管理员</option>
                                    <option value="ADMIN">超级管理员</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">名称：</td>
                            <td><input type="text" name="name"></td>
                        </tr>
                        <tr>
                            <td align="right">密码：</td>
                            <td><input type="password" name="password"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer2('addForm')"
                                                     value="提交"></td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </div>
        </td>
        <td valign="top" width="30%">
            <div>
                修改类型：
                <form id="modifyTypeForm" action="../manager/manage/modifyType">
                    <table>
                        <tr>
                            <td align="right">管理员id：</td>
                            <td><input type="text" name="managerId"></td>
                        </tr>
                        <tr>
                            <td align="right">新类型：</td>
                            <td>
                                <select name="newType">
                                    <option value="NORMAL" selected="true">普通管理员</option>
                                    <option value="ADMIN">超级管理员</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer2('modifyTypeForm')"
                                                     value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </div>
        </td>
        <td valign="top" width="40%">
            <div>
                修改密码：
                <form id="modifyPasswordForm" action="../manager/manage/modifyPassword">
                    <table>
                        <tr>
                            <td align="right">管理员id：</td>
                            <td><input type="text" name="managerId"></td>
                        </tr>
                        <tr>
                            <td align="right">新密码：</td>
                            <td><input type="password" name="newPassword"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer2('modifyPasswordForm')"
                                                     value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </div>
        </td>
    </tr>
</table>
</body>
</html>